package com.demo;

import java.util.concurrent.atomic.AtomicReference;

/**
 * CAS 线程安全
 * @author ytj
 * @date 2022/2/21
 */
public class Single6 {
    private static Single6 instance;

    private static  final AtomicReference<Single6> INSTANCE=new AtomicReference<>();

    private Single6(){

    }

    public static Single6 getInstance(){
        for (;;){
           Single6 instance=INSTANCE.get();
           if(instance!=null){
               return instance;
           }
           INSTANCE.compareAndSet(null,new Single6());
           return INSTANCE.get();
        }
    }
}
